<!--
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-18 19:05:08
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-28 15:39:15
 * @FilePath: \linePatrol\vue-element-plus-admin\src\views\Emergency\components\Distribute.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-05-30 15:00:30
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-09-28 15:35:18
 * @FilePath: \linePatrol\vue-element-plus-admin\src\views\Authorization\Dictionary\components\EditDictType.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="tsx">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch, ref, computed } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'
const { required } = useValidator()
import { useDictStore } from '@/store/modules/dictData'
import { EmergencyEventType } from '@/api/Emergency/type'
import { usePatrolGroupStore } from '@/store/modules/PlanGroupStore'
import { UserListAlltype } from '@/api/department/types'
const DictStore = useDictStore()
DictStore.setDict('pian_qat_type') //状态字典
const { formRegister, formMethods } = useForm()
const { setValues, getFormData, getElFormExpose } = formMethods
const FormData = ref({})
const GroupStore = usePatrolGroupStore()
if (GroupStore.getUserListAll.length == 0) {
  GroupStore.setUserListAll() //获取执行用户列表
}
const UserList = computed(() => {
  return GroupStore.getUserListAll
}) //执行用户列表
const schema = reactive<FormSchema[]>([
  {
    field: 'eventUuid',
    label: '台账uuid',
    component: 'Input',
    hidden: true,
    componentProps: {
      disabled: true
    }
  },
  {
    field: 'assignUser',
    label: '指派人员',
    component: 'Select',
    componentProps: {
      options: UserList.value.map((item: UserListAlltype) => {
        return {
          label: item.userName,
          value: item.userName
        }
      })
    },
    colProps: {
      span: 13
    }
  },

  {
    field: 'qatType',
    label: '验收类型',
    component: 'RadioGroup',
    colProps: {
      span: 20
    },
    componentProps: {
      options: DictStore.$state.pian_qat_type?.map((item) => {
        return {
          label: item.dictLabel,
          value: item.dictValue
        }
      })
    }
  },
  {
    field: 'qatUser',
    label: '验收人员',
    component: 'Select',
    componentProps: {
      options: UserList.value.map((item: UserListAlltype) => {
        return {
          label: item.userName,
          value: item.userName
        }
      })
    },
    colProps: {
      span: 13
    }
  },
  {
    field: 'endDate',
    label: '截止日期',
    component: 'DatePicker',
    componentProps: {
      type: 'datetime',
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    colProps: {
      span: 15
    }
  },
  {
    field: 'description',
    label: '处置要求',
    component: 'Input',
    colProps: {
      span: 20
    }
  }
])
const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<EmergencyEventType>>,
    default: () => null
  }
})
watch(
  () => props.currentRow,
  (currentRow) => {
    if (!currentRow) return
    FormData.value = { eventUuid: currentRow.uuid }
    setValues(FormData.value)
  },
  {
    deep: true,
    immediate: true
  }
)
// setValues(currentRow)
const submit = async () => {
  const elForm = await getElFormExpose()
  const valid = await elForm?.validate().catch((err) => {
    console.log(err)
  })
  if (valid) {
    const formData = await getFormData()
    return formData
  }
}
const rules = reactive({
  eventUuid: [required()],
  assignUser: [required()],
  qatType: [required()],
  qatUser: [required()],
  endDate: [required()],
  contacts: [required()],
  contactPhone: [required()]
})
defineExpose({
  submit
})
</script>
<template>
  <Form :rules="rules" :schema="schema" @register="formRegister" />
</template>
<style scoped>
/* ::v-deep是vue3提供的深度选择器，.el-form-item__label是element-plus官方定义的类 */
:deep(.el-col) {
  margin: 5px 0;
}
:deep(.el-form-item__label) {
  display: inline-block !important;
}
.label {
  font-size: 15px;
  font-weight: 800;
}
</style>
